/*
 * Created by seeker910 on 2015/5/29.
 */

Rsd.define('Rsd.Faith.pages.FiscalPiaoJuXinXiListPage', {
    extend: 'Rsd.Faith.pages.ListPage',
    requires: ['Rsd.controlEx.ComboBoxEnum','Rsd.Faith.controls.SuoShuQiInput'],
    xtype: 'list-piaoJu',
    border: false,
    tabTitle: '住房维修资金缴存信息',
    searchColumns:[
        {name:'SuoShuQi',text:'所属期',width:200,xtype:'ctrl-suoshuqi'},
        {name:'FaPiaoBianHao',text:'发票编号',width:250},
        {name:'XiaoQuBianHao',text:'小区编号',width:200},
        {name:'FangWuDaiMa',text:'房屋代码',width:250},
        {name:'YeZhuXingMing',text:'业主姓名',width:200},
        {name:'ZhuangTai',text:'状态',width:150, "xtype": "combobox-enum", "enum":"Rsd.Faith.Core.FaPiaoZhuangTai"}
        ],
    modelType: 'FiscalPiaoJuXinXiBiaoModel',
    readOnly:false,
    formFields: [
        {
            "name": "ShouFeiBiaoZhun",
            "label": {
                "text": "收费标准",
                "width": 80
            },
            "xtype": "combobox-enum",
            "valueMember": "value",
            enum:'Rsd.Faith.Core.ShouFeiBiaoZhunZZ'
        },
        {
            "name": "YingJiaoJinE",
            "label": {
                "text": "应交金额",
                "width": 80
            },
            "xtype": "number",
            "precision": 2
        },
        {
            "name": "ShiJiaoJinE",
            "label": {
                "text": "实交金额",
                "width": 80
            },
            "xtype": "number",
            "precision": 2
        },
        {
            "name": "JiaoNaRiQi",
            "label": {
                "text": "开票日期",
                "width": 80
            },
            "xtype": "date",
            "formatString": "yyyy-MM-dd"
        },
        {
            "name": "ZhuangTai",
            "label": {
                "text": "状态",
                "width": 80
            },
            "xtype": "text"
        },
        {
            "name": "YeZhuXingMing",
            "label": {
                "text": "业主姓名",
                "width": 80
            },
            "xtype": "text"
        },
        {
            "name": "FangWuDaiMa",
            "label": {
                "text": "房屋代码",
                "width": 80
            },
            "xtype": "text"
        },
        {
            "name": "FaPiaoBianHao",
            "label": {
                "text": "发票编号",
                "width": 80
            },
            "xtype": "text"
        },
        {
            "name": "CaoZuoYuanHao",
            "label": {
                "text": "操作员号",
                "width": 80
            },
            "xtype": "text"
        },
        {
            "name": "GouFangZongE",
            "label": {
                "text": "购房总额",
                "width": 80
            },
            "xtype": "number",
            "precision": 2
        },
        {
            "name": "FangWuLeiXing",
            "label": {
                "text": "房屋类型",
                "width": 80
            },
            "xtype": "combobox-enum",
            "enum":'Rsd.Faith.Core.FangWuLeiXing'
        },
        {
            "name": "FangWuXingZhi",
            "label": {
                "text": "房屋性质",
                "width": 80
            },
            "xtype": "combobox-enum",
            "enum":'Rsd.Faith.Core.FangWuXingZhi'
        },
        {
            "name": "Remark",
            "label": {
                "text": "备注",
                "width": 80
            },
            "xtype": "text"
        }
    ],
    sort:[{name:'JiaoNaRiQi',direction:'desc'}],
    gridColumns: [
        {
            "text": "序号",
            "xtype": "index",
            "width": 60,
            "sortable": false
        },
        {
            "name": "FaPiaoBianHao",
            "text": "发票编号",
            "dataindex": "FaPiaoBianHao",
            "sortable": false,
            align:'right',
            "width": 150,
            format:'format_fph',
            "nobr": true
        },
        {
            "name": "SuoShuQi",
            "dataIndex": "SuoShuQi",
            "sortable": false,
            "text": "所属期",
            align:'center',
            "index": 20,
            "exist": true,
            "xtype": "string",
            "width": 80,
            "nobr": true
        },
        {
            xtype:'enum',
            "name": "ZhuangTai",
            "text": "状态",
            "dataindex": "ZhuangTai",
            "sortable": false,
            align:'center',
            enum:{
                "name": "Rsd.Faith.Core.FaPiaoZhuangTai",
                "valueMember": "code",
                "items": [
                    {
                        "code": "DJ",
                        "value": 0,
                        "text": "待审核"
                    },
                    {
                        "code": "SH",
                        "value": 1,
                        "text": "已审核"
                    },
                    {
                        "code": "RZ",
                        "value": 2,
                        "text": "已入账"
                    }
                ]
            },
            "width": 80,
            "nobr": true
        },
        {
            "name": "FangWuDaiMa",
            "text": "房屋代码",
            align:'left',
            xtype: 'template',
            format:'fanWuFormat',
            "sortable": false,
            "width": 200,
            "nobr": true
        },
        {
            "name": "YeZhuXingMing",
            "text": "业主姓名",
            "sortable": false,
            "width": 70,
            "nobr": true
        },
        {
            "name": "FangWuLeiXing",
            "text": "房屋类型",
            "dataindex": "FangWuLeiXing",
            "sortable": false,
            align:'center',
            "width": 70,
            "xtype": "enum",
            "enum": {
                "name": "Rsd.Faith.Core.FangWuLeiXing",
                "valueMember": "code",
                "items": [
                    {
                        "code": "DC",
                        "value": 0,
                        "text": "多层"
                    },
                    {
                        "code": "XGC",
                        "value": 1,
                        "text": "小高层"
                    },
                    {
                        "code": "GC",
                        "value": 2,
                        "text": "高层"
                    },
                    {
                        "code": "CGC",
                        "value": 3,
                        "text": "超高层"
                    }
                ]
            },
            "nobr": true
        },
       {
           "name": "FangWuXingZhi",
           "text": "房屋性质",
           "dataindex": "FangWuXingZhi",
           "sortable": false,
           "width": 70,
           "xtype": "enum",
           "enum": {
               "name": "Rsd.Faith.Core.FangWuXingZhi",
               "valueMember": "code",
               "items": [
                   {
                       "code": "SP",
                       "value": 0,
                       "text": "商品房"
                   },
                   {
                       "code": "AZ",
                       "value": 1,
                       "text": "安置房"
                   },
                   {
                       "code": "LZ",
                       "value": 2,
                       "text": "廉租房"
                   },
                   {
                       "code": "SY",
                       "value": 3,
                       "text": "商业用房"
                   }
               ]
           },
           "nobr": true
       },
        {
            "name": "GouFangZongE",
            "text": "购房总额",
            "dataindex": "GouFangZongE",
            "sortable": false,
            "xtype": "number",
            "width": 100,
            "precision": 2
        },
        {
            "name": "ShouFeiBiaoZhun",
            "text": "收费标准",
            "dataindex": "ShouFeiBiaoZhun",
            "sortable": false,
             align:'center',
            "width": 100,
            xtype:'enum',
            enum:{
                "name": "Rsd.Faith.Core.ShouFeiBiaoZhunZZ",
                "valueMember": "value",
                "textMember": "text",
                "items": [
                    {
                        "code": "Unknown",
                        "value": 0,
                        "text": "未设置"
                    },
                    {
                        "code": "PV002",
                        "value": 2,
                        "text": "房价*2%"
                    },
                    {
                        "code": "PM5",
                        "value": 5,
                        "text": "5元/平方米"
                    },
                    {
                        "code": "PM15",
                        "value": 15,
                        "text": "15元/平方米"
                    },
                    {
                        "code": "PM20",
                        "value": 20,
                        "text": "20元/平方米"
                    },
                    {
                        "code": "PM30",
                        "value": 30,
                        "text": "30元/平方米"
                    },
                    {
                        "code": "PM40",
                        "value": 40,
                        "text": "40元/平方米"
                    }
                ]
            },
            "nobr": true
        },
        {
            "name": "YingJiaoJinE",
            "text": "应交金额",
            "dataindex": "YingJiaoJinE",
            "sortable": false,
            "xtype": "number",
            "width": 100,
            "precision": 2
        },
        {
            "name": "ShiJiaoJinE",
            "text": "实交金额",
            "dataindex": "ShiJiaoJinE",
            "sortable": false,
            "xtype": "number",
            "width": 100,
            "precision": 2
        },
        {
            "name": "JiaoCunFangShi",
            "text": "交存方式",
            "dataindex": "JiaoCunFangShi",
            "sortable": false,
            align:'center',
            "width": 100,
            xtype:'enum',
            enum:{
                "name": "Rsd.Faith.Core.JiaoCunFangShi",
                "valueMember": "code",
                "textMember": "text",
                "items": [
                    {
                        "code": "null",
                        "value": 0,
                        "text": "业主自交"
                    },
                    {
                        "code": "YZ",
                        "value": 0,
                        "text": "业主自交"
                    },
                    {
                        "code": "KFS",
                        "value": 1,
                        "text": "开发商代交"
                    }

                ]
            },
            "nobr": true
        },
        {
            "name": "JiaoNaRiQi",
            "text": "开票日期",
            "dataindex": "JiaoNaRiQi",
            "sortable": true,
             sortDirection:"desc",
            "xtype": "date",
            //"formatString": "yyyy-MM-dd",
            "width": 120
        },

        {
            "name": "CaoZuoYuanHao",
            "text": "操作员",
            "dataindex": "CaoZuoYuanHao",
            "sortable": false,
            "width": 70,
            "nobr": true
        },
        {
            "name": "Remark",
            "text": "备注",
            "dataindex": "Remark",
            "sortable": false,
            "width": 100,
            "nobr": true
        }
    ],
    titleField : 'FaPiaoBianHao',
    fangWuFormFields: [
        {
            "name": "XiaoQuBianHao",
            "label": {
                "text": "小区编号",
                "width": 80
            },
            "index": 0,
            readOnly:true,
            "xtype": "text"
        },
        {
            "name": "LouDongHao",
            "label": {
                "text": "楼栋号",
                "width": 80
            },
            "index": 0,
            "xtype": "text"
        },

        {
            "name": "DanYuanHao",
            "label": {
                "text": "单元号",
                "width": 80
            },
            "index": 0,
            "xtype": "number"
        },
        {
            "name": "ShiHao",
            "label": {
                "text": "室号",
                "width": 80
            },
            "index": 0,
            "xtype": "text"
        },
        {
            "name": "BianHao",
            "label": {
                "text": "编号",
                "width": 80
            },
            "index": 0,
            "xtype": "text"
        },
        {
            "name": "JianZhuMianJi",
            "label": {
                "text": "建筑面积",
                "width": 80
            },
            "index": 0,
            "xtype": "number",
            "format": "0.00"
        },
        {
            "name": "FangWuLeiXing",
            "label": {
                "text": "房屋类型",
                "width": 80
            },
            "index": 0,
            "xtype": "combobox-enum",
            "enum":'Rsd.Faith.Core.FangWuLeiXing'
        },
        {
            "name": "FangWuXingZhi",
            "label": {
                "text": "房屋性质",
                "width": 80
            },
            "index": 0,
            "xtype": "combobox-enum",
            "enum":'Rsd.Faith.Core.FangWuXingZhi'
        },
        {
            "name": "ShouQiJiaoCunJinE",
            "label": {
                "text": "首期缴存金额",
                "width": 80
            },
            "index": 0,
            "xtype": "number",
            "format": "0.00"
        },
        {
            "name": "YeZhuXingMing",
            "label": {
                "text": "业主姓名",
                "width": 80
            },
            "index": 0,
            "xtype": "text"
        },
        {
            "name": "BeiYongDiZhi",
            "label": {
                "text": "备用地址",
                "width": 80
            },
            "index": 0,
            "xtype": "text"
        },

        {
            "name": "Remark",
            "label": {
                "text": "备注",
                "width": 80
            },
            "index": 200,
            "xtype": "text"
        }
    ],
    /*
     * */
    constructor: function (config) {
        config = config || {};
        Rsd.apply(this, config);
    },
    /*
    * */
    format_fph:function format_fph(row)
    {
        if(Rsd.isEmpty(row))
        {
            return [];
        }
        var me = this;
        if(row['FaPiaoBianHao'] == '')
        {
            return [Rsd.blankspan(1),Rsd.btn('打印发票',function () {
                var _data = {
                    KFS:'恒大房地产开发公司',
                    YZXM:'李四',
                    DH:'13888888888',
                    ZZDZ:'凤凰苑6栋25206室',
                    ZCS:31,
                    DSCS:30,
                    ZHS:60,
                    JZMJ:120,
                    SPFJZMJ:120,
                    SPFBZ:45,
                    DZ:'扬中市三茅中电路281号',
                    LDBH:'88888888888',
                    LDH:'20幢/塔楼A',
                    YJJE:3600,
                    JEDX:Rsd.formatCurrencyCN(3600),
                    NIAN:new Date().format('yyyy'),
                    YUE:new Date().format('MM'),
                    RI:new Date().format('dd'),
                    KPR:'张三',
                    FHR:'小王',
                    SKDW:'扬中市住宅专项维修资金管理中心'

                };
                var key = 'FP_' + row['Id'];
                Rsd.writeSession(key,_data);
                window.open('print.html?tpl=JiaoCunFaPiao&key='+key);
            })];
        }

        if(row['ZhuangTai'] == 'DJ')
        {
            var _fn = function () {
                Rsd.yesOrNo('确认发票(' + row['FaPiaoBianHao'] + ')应缴存资金'+row['YingJiaoJinE']+'元,\r\n已缴存到指定银行账户。',function () {
                    Rsd.app.requestService("Fiscal.JiaoCunQueRenZZ",{faPiaoHaoMa:row['FaPiaoBianHao']},function (data) {
                        //console.log(data);
                        if(data.success)
                        {
                            me.load();
                        }else
                        {
                            Rsd.alert(data.msg);
                        }
                    });
                });
            };
            var _btn = Rsd.button('确认到账',_fn);
            _btn.title = '确认发票(' + row['FaPiaoBianHao'] + ')资金是否缴存到指定银行账户。';
            return [Rsd.newLine(),_btn,Rsd.blankspan(1),Rsd.btn('入账')];
        }
        if(row['ZhuangTai'] == 'SH')
        {
            var _fn = function () {
                //alert('将发票(' + row['FaPiaoBianHao'] + ')缴存资金，计入分账户明细账。');
                Rsd.app.requestService("Fiscal.JiaoCunRuZhangZZ",{faPiaoHaoMa:row['FaPiaoBianHao']},function (data) {
                    //console.log(data);
                    if(data.success)
                    {
                        me.load();
                    }else
                    {
                        Rsd.alert(data.msg);
                    }
                });
            };
            var _btn = Rsd.btn('入账',_fn);
            _btn.title = '将发票(' + row['FaPiaoBianHao'] + ')缴存资金，计入分账户明细账。';
            return [Rsd.newLine(),_btn];
        }
        return [];
    },
    /*
    * */
    fanWuFormat:function fanWuFormat(row)
    {
        var me = this;
        if(!row)
        {
            return [];
        }
        var _span = document.createElement('span');
        _span.style.maxWidth = '150px';
        _span.style.overflow = 'hidden';
        _span.style.display = 'inline-block';
        _span.style.textOverflow = 'ellipsis';
        _span.title = '查看房屋基本信息：' + row['FangWuDaiMa'];
        var  _link = document.createElement('a');
        _span.appendChild(_link);

        _link.href='#';
        _link.innerHTML = row['FangWuDaiMa'];
        $(_link).click (function(){
            Rsd.app.requestService('biz.GetList',{
                modeltype:'Rsd.Faith.Models.InfoFangWuXinXiBiaoModel',
                pagesize:1,
                where:[{name:'BianHao',value:row['FangWuDaiMa'],op:'equals'}]},function (data) {

                if(data.data.total>0)
                {
                    Rsd.app.showModelView('Rsd.Faith.Models.InfoFangWuXinXiBiaoModel',me.fangWuFormFields,data.data.rows[0],"房屋信息",['Cancel'],true);
                }else
                {
                    Rsd.alert('房屋信息不存在');
                }

            });
        } );

        var _fn  = function () {
            Rsd.showWaiting(me.id);
            Rsd.app.requestService('biz.GetList',{
                modeltype:'Rsd.Faith.Models.BookFenHuZhangModel',
                pagesize:1,
                where:[{name:'FangWuBianHao',value:row['FangWuDaiMa'],op:'equals'}]},
                function (data) {
                    Rsd.closeWaiting(me.id);
                    if(data.data.total>0)
                    {
                        Rsd.create('Rsd.Faith.dialogs.InfoFenHuZhangDialog',{data:data.data.rows[0]}).showDialog();
                    }else
                    {
                        Rsd.alert('票据未入账,无法查看账目详细信息');
                    }

            });

        };

        return [_span,Rsd.blankspan(2),Rsd.button('分户账',row['ZhuangTai'] == 'DJ'?null:_fn)] ;
    }

});